package com.chris.vue.controller;

import com.chris.vue.models.base.NetRequest;
import com.chris.vue.models.items.MenuInfoItem;
import com.chris.vue.models.items.MenuItem;
import com.chris.vue.models.net.NetResult;
import com.chris.vue.models.param.LoginParam;
import com.chris.vue.models.result.JwtResult;
import com.chris.vue.models.result.UserInfoResult;
import com.chris.vue.service.UserService;
import com.google.gson.Gson;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

/**
 * Created by Chris Chan
 * 2020/8/13 7:47
 * Use for:
 * Explain:
 */
@Log4j2
@RestController
@RequestMapping("api/user")
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    Gson gson;

    @PostMapping("login")
    public NetResult<JwtResult> login(@RequestBody NetRequest<LoginParam> param) {
        log.info(gson.toJson(param));
        return NetResult.ok(new JwtResult(UUID.randomUUID().toString()));
    }

    @GetMapping("getInfo")
    public NetResult<UserInfoResult> getInfo() {
        List<MenuItem> menuItems = userService.getMenus();
        List<MenuInfoItem> menuInfoItems = userService.getMenuInfos();
        //这个icon显示不出来
        String icon = "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3511831835,544094419&fm=26&gp=0.jpg";
        return NetResult.ok(new UserInfoResult("chenfabao", icon, 42, menuItems, menuInfoItems, "Admin"));
    }

    @PostMapping("logout")
    public NetResult<Boolean> logout() {
        return NetResult.ok(true);
    }
}
